/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package caro.client.controller;

import caro.app.protocolprovider.ProtocolProcessing;
import caro.client.gui.PopupTable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author NQ
 */
public class PopupTableCtrl {
    private PopupTable popupView;
    private Socket clientSocket;
    public PopupTableCtrl(Socket s, PopupTable popupView){
        this.clientSocket = s;
        this.popupView = popupView;
        this.popupView.addInviteListener(new PopupTableListener());
    }
    class PopupTableListener implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
            PrintWriter writer = null;
            try {
                writer = new PrintWriter(clientSocket.getOutputStream());
                String username = popupView.getUserInvited();
                String message = ProtocolProcessing.getPlayRequest(username);
                writer.println(message);
                writer.flush();
            } catch (IOException ex) {
                Logger.getLogger(PopupTableCtrl.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
    }
}
